unit spr_Towns;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, shbl_Directory, DB, FIBDataSet, pFIBDataSet, ActnList,
  Buttons, StdCtrls, GridsEh, DBGridEh, ComCtrls, ExtCtrls, ToolWin,
  DBCtrlsEh, Mask, DBLookupEh, FIBDatabase, pFIBDatabase, PropFilerEh,
  PropStorageEh, XLSExportComp, DBGridEhGrouping;

type
  TsprTowns = class(TshblDirectory)
    dsReferID: TFIBIntegerField;
    dsReferNAME: TFIBStringField;
    dsReferCODECALL: TFIBStringField;
    dsReferCODECALLADD: TFIBStringField;
    dsReferREFSERVICE: TFIBStringField;
    dsReferCODE: TFIBIntegerField;
    dsReferLOCAL: TFIBSmallIntField;
    dsReferTOWN_AREA: TFIBIntegerField;
    dsReferFULL_NAME: TFIBStringField;
    dsReferTT_TOWNTYPE: TFIBStringField;
    dsReferTT_SHORT_TOWNTYPE: TFIBStringField;
    dsReferTOWN_TYPE_ID: TFIBIntegerField;
    dsReferAREA_NAME: TFIBStringField;
    dsReferREGION: TFIBStringField;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    DBEditEh1: TDBEditEh;
    DBCheckBoxEh1: TDBCheckBoxEh;
    Label4: TLabel;
    DBEditEh4: TDBEditEh;
    Label5: TLabel;
    DBEditEh5: TDBEditEh;
    Label6: TLabel;
    DBEditEh6: TDBEditEh;
    DBEditEh2: TDBEditEh;
    DBEditEh3: TDBEditEh;
    Label7: TLabel;
    dsTownTypes: TpFIBDataSet;
    dsTownTypesID: TFIBIntegerField;
    dsTownTypesNAME: TFIBStringField;
    DBLookupComboboxEh1: TDBLookupComboboxEh;
    DBEditEh7: TDBEditEh;
    Label8: TLabel;
    Label9: TLabel;
    DBLookupComboboxEh2: TDBLookupComboboxEh;
    dsTownArea: TpFIBDataSet;
    dscTownTypes: TDataSource;
    dscTownArea: TDataSource;
    Label10: TLabel;
    dsTownAreaID: TFIBIntegerField;
    dsTownAreaAREA_NAME: TFIBStringField;
    eNameSearch: TDBEditEh;
    cbLocalSearch: TDBCheckBoxEh;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure eNameSearchChange(Sender: TObject);
    procedure dsReferBeforeEdit(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  sprTowns: TsprTowns;

implementation

uses uMAIN, uDM, shbl_GridWindow;

{$R *.dfm}

procedure TsprTowns.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  dsTownArea.Close;
  dsTownTypes.Close;
end;

procedure TsprTowns.eNameSearchChange(Sender: TObject);
begin
  inherited;
  aAddSQLString.Clear;
  if cbLocalSearch.State = cbChecked then
    aAddSQLString.Append('and t.local = 1');
  if cbLocalSearch.State = cbUnchecked	then
    aAddSQLString.Append('and t.local = 0');
  if eNameSearch.Text <> '' then
    aAddSQLString.Append(' and t.name starting upper(''' + eNameSearch.Text + ''')');
  Timer1.Enabled := false;
  Timer1.Enabled := true;
end;

procedure TsprTowns.dsReferBeforeEdit(DataSet: TDataSet);
begin
  inherited;
  if not dsTownArea.Database.Connected then exit;

  if dsTownArea.Active = false then dsTownArea.Open;
  if dsTownTypes.Active = false then dsTownTypes.Open;
end;

end.
